s = input().split(" ")
n = int(s[0])
m = int(s[1])
arr = [None] * n
for i in range(n):
    arr[i] = [int(x) for x in input().split(" ")]
def isFour(arr):
    for i in range(n):
        for j in range(m):
            # 右
            if j <= m - 4:
                if arr[i][j] == arr[i][j + 1] == arr[i][j + 2] == arr[i][j + 3]:
                    # print("连续相等的数字为 " + str(arr[i][j]))
                    return True
            # 下
            if i <= n - 4:
                if arr[i][j] == arr[i + 1][j] == arr[i + 2][j] == arr[i + 3][j]:
                    # print("连续相等的数字为 " + str(arr[i][j]))
                    return True
            # 右下
            if i <= n - 4 and j <= m - 4:
                if arr[i][j] == arr[i + 1][j + 1] == arr[i + 2][j + 2] == arr[i + 3][j + 3]:
                    # print("连续相等的数字为 " + str(arr[i][j]))
                    return True
            # 右上
            if i >= 3 and j <= m - 4:
                if arr[i][j] == arr[i - 1][j + 1] == arr[i - 2][j + 2] == arr[i - 3][j + 3]:
                    # print("连续相等的数字为 " + str(arr[i][j]))
                    return True
    return False

if isFour(arr):
    print("YES")
else:
    print("NO")
